package com.gxuwz.eschool;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;

import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
//用水记录
public class WaterRecordActivity extends AppCompatActivity {

    private LinearLayout ll_all;
    private TextView tv_all;
    private View vw_all;
    private LinearLayout ll_consume;
    private TextView tv_consume;
    private View vw_consume;
    private LinearLayout ll_recharge;
    private TextView tv_recharge;
    private View vw_recharge;
    private LinearLayout ll_other;
    private TextView tv_other;
    private View vw_other;
    private FragmentTransaction fragmentTransaction;
    private ImageView iv_back;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_water_record);
        ll_all = findViewById(R.id.ll_all);
        tv_all = findViewById(R.id.tv_all);
        vw_all = findViewById(R.id.vw_all);
        ll_consume = findViewById(R.id.ll_consume);
        tv_consume = findViewById(R.id.tv_consume);
        vw_consume = findViewById(R.id.vw_consume);
        ll_recharge = findViewById(R.id.ll_recharge);
        tv_recharge = findViewById(R.id.tv_recharge);
        vw_recharge = findViewById(R.id.vw_recharge);
        ll_other = findViewById(R.id.ll_other);
        tv_other = findViewById(R.id.tv_other);
        vw_other = findViewById(R.id.vw_other);

        ll_all.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                setFragment(ll_all);
            }
        });
        ll_consume.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                setFragment(ll_consume);
            }
        });
        ll_recharge.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                setFragment(ll_recharge);
            }
        });
        ll_other.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                setFragment(ll_other);
            }
        });
        iv_back = findViewById(R.id.iv_back);
        iv_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                FragmentManager fragmentManager = getSupportFragmentManager();
                // 检查是否有Fragment可以回退
                if (fragmentManager.getBackStackEntryCount() > 0) {
                    fragmentManager.popBackStack(); // 返回上一个Fragment
                } else {
                    // 如果没有Fragment可以回退，可以结束当前Activity
                    finish();
                }
            }
        });
    }


    private void setFragment(LinearLayout selected) {
        updateTextViewIcons(selected);

    }
    private void updateTextViewIcons(LinearLayout selected) {
        int defaultColor = Color.BLACK; // 默认颜色
        int selectedTextColor = Color.RED; // 选中文本颜色（示例）

        // 根据selected决定哪个TextView变为红色
        if (selected == ll_all) {
            tv_all.setTextColor(selectedTextColor);
            vw_all.setBackgroundColor(selectedTextColor);
            tv_consume.setTextColor(defaultColor);
            vw_consume.setBackgroundColor(defaultColor);
            tv_recharge.setTextColor(defaultColor);
            vw_recharge.setBackgroundColor(defaultColor);
            tv_other.setTextColor(defaultColor);
            vw_other.setBackgroundColor(defaultColor);
        } else if (selected == ll_consume) {
            tv_consume.setTextColor(selectedTextColor);
            vw_consume.setBackgroundColor(selectedTextColor);
            tv_all.setTextColor(defaultColor);
            vw_all.setBackgroundColor(defaultColor);
            tv_recharge.setTextColor(defaultColor);
            vw_recharge.setBackgroundColor(defaultColor);
            tv_other.setTextColor(defaultColor);
            vw_other.setBackgroundColor(defaultColor);

        }else if (selected == ll_recharge) {
            tv_recharge.setTextColor(selectedTextColor);
            vw_recharge.setBackgroundColor(selectedTextColor);
            tv_all.setTextColor(defaultColor);
            vw_all.setBackgroundColor(defaultColor);
            tv_consume.setTextColor(defaultColor);
            vw_consume.setBackgroundColor(defaultColor);
            tv_other.setTextColor(defaultColor);
            vw_other.setBackgroundColor(defaultColor);
        }else if (selected == ll_other) {
            tv_other.setTextColor(selectedTextColor);
            vw_other.setBackgroundColor(selectedTextColor);
            tv_all.setTextColor(defaultColor);
            vw_all.setBackgroundColor(defaultColor);
            tv_recharge.setTextColor(defaultColor);
            vw_recharge.setBackgroundColor(defaultColor);
            tv_consume.setTextColor(defaultColor);
            vw_consume.setBackgroundColor(defaultColor);
        }
    }

}